#pragma once
#include "DXAMLCommon.h"
#include "CXcpObjectBase.h"
#include "IPALExecuteOnUIThread.h"
#include "CXcpObjectThreadSafeAddRefPolicy.h"


class ImageTaskDispatcher :
	public CXcpObjectBase<IPALExecuteOnUIThread,CXcpObjectThreadSafeAddRefPolicy>
{

public: 
	static HRESULT Create(CCoreServices * pCore, ImageTaskDispatcher * * ppDispatcher);
	HRESULT QueueTask(struct IImageTask * pTask);
	HRESULT QueueTaskTakeReference(struct IImageTask * pTask);
	virtual HRESULT Execute();

protected: 
	ImageTaskDispatcher();
	virtual ~ImageTaskDispatcher();
	HRESULT Initialize(CCoreServices * pCore);
	CCoreServices * m_pCore;
	xdevector<IImageTask *> m_tasks;
	struct IPALCriticalSection * m_pTaskLock;
	XBOOL m_hasCallbackQueued;
};